package cn.cycleif.app.controller;

import cn.cycleif.app.domain.dto.UserLoginDTO;
import cn.cycleif.app.domain.vo.VerifyCodeVO;
import cn.cycleif.app.service.LoginService;
import cn.cycleif.util.R;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date: 25/1/22-17:45
 * @Desc:
 */
@RestController
@RequestMapping("/api/user")
@Tag(name = "登录登出", description = "账号登录登出")
@SaIgnore
public class LoginController {

  @Autowired
  private LoginService loginService;

  @GetMapping("/captcha")
  @Operation(summary = "获取验证码")
  public R<VerifyCodeVO> captcha() {
    return loginService.getCaptcha();
  }

  @PostMapping("/login")
  @Operation(summary = "登录")
  public R<String> login(@RequestBody UserLoginDTO dto) {
    return loginService.login(dto);
  }

  @GetMapping("/checkLogin")
  @Operation(summary = "检查登录")
  public R<String> checkLogin() {
    return loginService.checkLogin();
  }

  @GetMapping("/logout")
  @Operation(summary = "退出登录")
  public R<String> logout() {
    StpUtil.logout();
    return R.success("退出成功");
  }

}
